// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: Implementation of CDelayedDelete.
//   $Id$

#include "stdafx.h"
#include "DelayedDelete.h"

CDelayedDelete::CDelayedDelete()
	:m_bDeleteOK(true)
	,m_bPleaseDelete(false)
{

}
CDelayedDelete::~CDelayedDelete()
{
}

void CDelayedDelete::RequestDeleteAtEarliestConvenience()
{
	m_bPleaseDelete = true;
	OnDeleteRequest();
	HonourDeletionRequests();
}

void CDelayedDelete::EnterDeletionPostponementState()
{
	m_bDeleteOK = false;
}

void CDelayedDelete::ExitDeletionPostponementState()
{
	m_bDeleteOK = true;
	HonourDeletionRequests();
}

void CDelayedDelete::HonourDeletionRequests()
{
	try
	{
		if(m_bDeleteOK && m_bPleaseDelete)
			delete this;
	}
	catch(...)
	{
	}
}

bool CDelayedDelete::IsInDeletionPostponementState()
{
	return !m_bDeleteOK;
}

bool CDelayedDelete::IsAwaitingDeletion()
{
	return (!m_bDeleteOK && m_bPleaseDelete);
}
